<template>
  <page-header-wrapper :title="false">
    <a-card>
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="筛选">
                <a-input :value="value" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :md="(!advanced && 8) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" :loading="loading" @click="handleSearch(queryParam)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
                <!-- <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'" />
                </a> -->
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- <div class="table-operator">
        <a-button type="primary" icon="plus" @click="handleCreate()">新增记录</a-button>
      </div> -->

      <a-table ref="table" size="default" rowKey="key" :columns="columns" :data-source="loadData">
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="orderType" slot-scope="text, record">
          <template>
            <div v-if="record.orderType == '0'">销售订单</div>
            <div v-if="record.orderType == '1'">售后订单</div>
          </template>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a-tag color="#428bca" @click="handleEdit(record)">进入</a-tag>
          </template>
        </span>
        <!-- <span slot="orderType" slot-scope="text, record">
          <template>
            <div v-if="record.status == 0">处理中</div>
            <div v-if="record.status == 1">待付款</div>
            <div v-if="record.status == 2">已付款</div>
          </template>
        </span> -->
        <span slot="orderStatus" slot-scope="text, record">
          <template v-if="record.orderType == '0'">
            <div v-if="record.orderStatus == 0">未付款</div>
            <div v-if="record.orderStatus == 1">已付款</div>
          </template>
          <template v-if="record.orderType == '1'">
            <div v-if="record.orderStatus == 0 || record.orderStatus == 1">未付款</div>
            <div v-if="record.orderStatus == 2">已支付</div>
          </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { getMemberOrderListUsingPOST } from '@/api/api/huiyuanguanli.ts'
export default {
  name: 'MemberListDetialSellrecord',
  components: {
  },
  data() {
    return {
      mdl: null,
      priceMdl: null,
      visible: false,
      priceVisible: false,
      value: '',
      confirmLoading: false,
      priceLoading: false,
      // 高级搜索 展开/关闭
      loading:false,
      advanced: false,
      // 查询参数
      queryParam: {
        pageNo:1,
        pageSize:10,
        queryCondition:'',
        status:''
      },
      // 表头
      columns: [
        {
          title: '订单ID',
          dataIndex: 'id',
        },
        {
          title: '订单类型',
          dataIndex: 'orderType',
          scopedSlots: { customRender: 'orderType' },
        },
        {
          title: '销售日期',
          dataIndex: 'orderDate',
        },
        {
          title: '创建人',
          dataIndex: 'creatorName',
        },
        {
          title: '销售员',
          dataIndex: 'empName',
        },
        {
          title: '归属店',
          dataIndex: 'storeName',
        },
        {
          title: '订单金额(元)',
          dataIndex: 'amount',
        },
        {
          title: '状态',
          dataIndex: 'orderStatus',
          scopedSlots: { customRender: 'orderStatus' },
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '180px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: [],
      optionAlertShow: false,
    }
  },
  created() {
    this.handleSearch(this.queryParam)
  },
  methods: {
    handleSearch() {
      this.loading= true
      getMemberOrderListUsingPOST({...this.queryParam,memId:this.$route.params.id})
        .then((res) => {
          this.loadData = res.data.list
          this.loading= false
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handleEdit (record) {
      if(record.orderType == 0){
        this.$router.push({ path: `/cashier/profile/index/${record.id}` })
      }else{
        this.$router.push({ path: `/service/service/detail/${record.id}` })
      }
    },
    handleDelete(record) {
      this.$confirm({
        title: '删除',
        content: '你确定要删除这个跟进吗？',
        okText: '确认',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          console.log('OK')
        },
        onCancel() {
          console.log('Cancel')
        },
      })
    },
  },
}
</script>
